package com.amumu.netctoss.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.amumu.netctoss.dao.CostDao;
import com.amumu.netctoss.entity.Cost;
/**
 * 姿费管理
 */
@Controller
@Scope("prototype")
public class CostAction extends BaseAction {

	@Resource
	private CostDao dao;
	private List<Cost> costList;
	private Cost cost;
	private String order;
	private String seq;
	private Map<String, Object> statusOptions;
	
	
	public String findAll() {
		System.out.println("dao:"+dao);
		try {
			setPageCount(dao.getPageCount(PAGE_SIZE));
			if(order!=null&&order.length()>0){
				costList = dao.findOrderBy(page, PAGE_SIZE, order, seq);
			}else{
				costList = dao.findAll(page, PAGE_SIZE);
			}
			statusOptions = dao.getStatusOptions();
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		return "success";
	}

	//姿费详情
	public String detail(){
		try {
			System.out.println("dao:"+dao);
			statusOptions = dao.getStatusOptions();
			cost = dao.findById(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String save(){
		try {
			dao.save(cost);
			ok = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String start(){
		try {
			dao.start(id);
			ok = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String delete(){
		try {
			dao.delete(id);
			ok = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String toUpdate(){
		try {
			cost = dao.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String update(){
		try {
			dao.update(cost);
			System.out.println("修改姿费成功");
			ok = true;
		} catch (Exception e) {
			System.out.println("捕获异常");
			e.printStackTrace();
		}
		System.out.println("finish");
		return SUCCESS;
	}
	
	public String verifyName(){
		try {
			cost = dao.findByName(cost.getName());
			if(cost==null){
				ok = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	//getter and setter
	public Map<String, Object> getStatusOptions() {
		return statusOptions;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getSeq() {
		return seq;
	}

	public void setSeq(String seq) {
		this.seq = seq;
	}

	public Cost getCost() {
		return cost;
	}

	public void setCost(Cost cost) {
		this.cost = cost;
	}

	public List<Cost> getCostList() {
		return costList;
	}

	public void setCostList(List<Cost> costList) {
		this.costList = costList;
	}

}
